import java.util.ArrayList;
import java.util.Iterator;

public class Solution284 implements Iterator<Integer>{
    Iterator<Integer> i;
    Integer nextElement;

    public Solution284(Iterator<Integer> iterator) {
        i=iterator;
        nextElement=iterator.next();
    }

    public Integer peek() {
        return nextElement;
    }

    @Override
    public Integer next() {
        Integer t=nextElement;
        if (i.hasNext()) {
            nextElement = i.next();
        }else {
            nextElement = null;
        }
        return t;
    }

    @Override
    public boolean hasNext() {
        return nextElement!=null;
    }

    public static void main(String[] args) {
        ArrayList<Integer> arrayList=new ArrayList<>();
        arrayList.add(1);arrayList.add(2);arrayList.add(3);
        Solution284 solution284=new Solution284(arrayList.iterator());
        System.out.println(solution284.next());
        System.out.println(solution284.peek());
        System.out.println(solution284.next());
        System.out.println(solution284.next());
        System.out.println(solution284.hasNext());
    }
}
